//
//  CustomSketchMapTableView.m
//  AmountBody
//
//  Created by smm on 2018/1/11.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomSketchMapTableView.h"
#import "CustomSketchMapTableViewCell.h"

@implementation CustomSketchMapTableView
-(void)loadViewForSketchMap
{
    CGFloat buttonH = 40;
    CGFloat l_jianGe = 7;
    CGFloat jianGe = 20;
    self.backImage = [[UIImageView alloc]init];
    [self addSubview:_backImage];
    UIImage * image = [UIImage imageNamed:@"xinxifudongbeijing"];
    // 指定为拉伸模式，伸缩后重新赋值
    image = [image stretchImageWithInsetsTop:jianGe left:jianGe bottom:jianGe right:jianGe];
    self.backImage.image = image;
    self.backImage.userInteractionEnabled = YES;
    [self.backImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
        
    }];
    self.backView = [[UIView alloc]init];
    [self.backImage addSubview:self.backView];
    [self.backView setYuanJiaoForRadius:l_jianGe andMasks:YES];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.backImage).insets(UIEdgeInsetsMake(l_jianGe, l_jianGe, l_jianGe, l_jianGe));
        
    }];
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.estimatedRowHeight = 40;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.backView addSubview:self.tableView];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.backImage).insets(UIEdgeInsetsMake(10, 10, buttonH, 10));
    }];
    
    
    _fd_leftButton = [[UIButton alloc]init];
    [self.backView addSubview:_fd_leftButton];
    [_fd_leftButton setTitle:@"量体示意图" forState:UIControlStateNormal];
    [_fd_leftButton addTarget:self action:@selector(leftButtonFunc:) forControlEvents:UIControlEventTouchUpInside];
//    _fd_leftButton.backgroundColor = RGBColorAlpha(255, 66, 89, 1);
    [_fd_leftButton setBackgroundImage:[UIImage imageNamed:@"buttonChoose"] forState:UIControlStateNormal];
    [_fd_leftButton setTitleColor:RGBColorAlpha(255, 66, 89, 1) forState:UIControlStateNormal];
    _fd_leftButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_fd_leftButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_tableView.mas_bottom).offset(0);
        make.height.equalTo(@(buttonH));
        make.left.equalTo(self.backView).with.offset(0);
        make.width.equalTo(self.backView).multipliedBy(0.5);
        make.bottom.equalTo(self.backView).offset(-0);
    }];
    //    [_fd_leftButton addLayerRectCorner:UIRectCornerBottomLeft andRadius:10.0];
    _fd_rightButton = [[UIButton alloc]init];
    [self.backView addSubview:_fd_rightButton];
    [_fd_rightButton setTitle:@"量体视频" forState:UIControlStateNormal];
    [_fd_rightButton addTarget:self action:@selector(rightButtonFunc:) forControlEvents:UIControlEventTouchUpInside];
//    _fd_rightButton.backgroundColor = RGBColorAlpha(44, 44, 44, 1);
     [_fd_rightButton setBackgroundImage:[UIImage imageNamed:@"buttonNoChoose"] forState:UIControlStateNormal];
    [_fd_rightButton setTitleColor:ShenZi_Color forState:UIControlStateNormal];
    _fd_rightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_fd_rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_fd_leftButton);
        make.height.equalTo(@(buttonH));
        make.right.equalTo(self.backView).with.offset(0);
        make.width.equalTo(self.backView).multipliedBy(0.5);
        make.bottom.equalTo(self.backView).offset(0);
    }];

}

#pragma mark -- tableViewDelegate and dataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        if (_hasInfo) {
            return 4;
        }else{
            return 0;
        }
       
    }else{
        return 1;
    }
    
}
#pragma mark - 懒加载

- (NSMutableArray *)dataArray;
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray array]init];
        NSArray * nameArr = [NSArray arrayWithObjects:@"客户昵称：",@"客户名称：",@"身高：",@"体重：",@"电话：",@"客户单号：",@"邮箱：",@"备注：", nil];
        NSArray * valueArr = [NSArray arrayWithObjects:@"客户昵称value",@"客户名称value",@"身高value",@"体重value",@"电话value",@"客户单号value",@"邮箱value",@"备注value备注value备注value备注value备注value备注value", nil];
        for (int i=0; i<nameArr.count; i++) {
            EssentialModel * model =[[EssentialModel alloc]init
                                     ];
            model.name = [nameArr objectAtIndex:i];
            model.value = [valueArr objectAtIndex:i];
            [_dataArray addObject:model];
        }
    }
    return _dataArray;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EssentialModel * model = [self.dataArray objectAtIndex:indexPath.row*2];
    EssentialModel * model2 = [self.dataArray objectAtIndex:indexPath.row*2+1];
    CustomSketchMapTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CustomSketchMapTableViewCell"];
    if (cell == nil) {
        cell = [[CustomSketchMapTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomSketchMapTableViewCell"];
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
    }
    
    switch (indexPath.section) {
        case 0:
        {
            if (_hasInfo) {
                if (indexPath.row == 3) {
                    cell.hasLine = NO;
                }else{
                    cell.hasLine = YES;
                }
                [cell setCellWithModel:model andModel:model2];
            }
            
        }
            break;
        case 1:
        {
            [cell setCellWithImage:@""];
        }
            break;
        case 2:
        {
            [cell setCellWithContent:@"例如我需要一张白色但是中间有一个透明的圆的图片来覆盖在图片上处理圆角头像的问题，该怎么绘制才能得出这张图片呢，我并不想直接把头像绘制成圆形。例如我需要一张白色但是中间有一个透明的圆的图片来覆盖在图片上处理圆角头像的问题，该怎么绘制才能得出这张图片呢，我并不想直接把头像绘制成圆形。例如我需要一张白色但是中间有一个透明的圆的图片来覆盖在图片上处理圆角头像的问题，该怎么绘制才能得出这张图片呢，我并不想直接把头像绘制成圆形。例如我需要一张白色但是中间有一个透明的圆的图片来覆盖在图片上处理圆角头像的问题，该怎么绘制才能得出这张图片呢，我并不想直接把头像绘制成圆形。" andName:@"胸围"];
        }
            break;
        default:
            break;
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
#pragma mark - 手势按钮方法
-(void)leftButtonFunc:(UIButton *)button
{
    [_fd_leftButton setBackgroundImage:[UIImage imageNamed:@"buttonChoose"] forState:UIControlStateNormal];
    [_fd_rightButton setBackgroundImage:[UIImage imageNamed:@"buttonNoChoose"] forState:UIControlStateNormal];
}

-(void)rightButtonFunc:(UIButton *)button
{
    [_fd_rightButton setBackgroundImage:[UIImage imageNamed:@"buttonChoose"] forState:UIControlStateNormal];
    [_fd_leftButton setBackgroundImage:[UIImage imageNamed:@"buttonNoChoose"] forState:UIControlStateNormal];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
